//
//  EditCharteredOrderViewController.m
//  didacar
//
//  Created by Yang Yuexia on 15/11/30.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "EditCharteredOrderViewController.h"
#import "EditCharteredOrderCell.h"
#import "EditCharteredOrderNextViewController.h"

@interface EditCharteredOrderViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) NSArray *singleDataList;

@property (strong, nonatomic) NSArray *doubleDataList;

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIButton *nextButton;

@property (assign, nonatomic) BOOL isSingle;

@property (weak, nonatomic) IBOutlet UIView *sectionFooterView;

@property (weak, nonatomic) IBOutlet UIView *slideView;

@property (weak, nonatomic) IBOutlet UIButton *singleButton;

@property (weak, nonatomic) IBOutlet UIButton *doubleButton;

@property (weak, nonatomic) IBOutlet UIButton *allDayButton;

@property (assign, nonatomic) NSInteger charteredBusType; // 包车类型

- (IBAction)singleAction:(id)sender;

- (IBAction)doubleAction:(id)sender;

- (IBAction)allDayAction:(id)sender;

- (IBAction)nextButtonAction:(id)sender;

@end

@implementation EditCharteredOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"填写包车订单";
    self.isSingle = NO;
    [self doubleAction:nil];
    self.singleDataList = @[@[@"出发地",@"目的地"],@[@"出发时间"],@[@"乘车人数",@"包车数量"]];
    self.doubleDataList = @[@[@"出发地",@"目的地"],@[@"出发时间",@"返程时间"],@[@"乘车人数",@"包车数量"]];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.nextButton.layer.cornerRadius = 4.0;
    self.nextButton.layer.masksToBounds = YES;
}

#pragma mark ---- 列表代理 ----
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.isSingle) {
        return self.singleDataList.count;
    }else{
        return self.doubleDataList.count;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.isSingle) {
        return [self.singleDataList[section] count];
    }else{
        return [self.doubleDataList[section] count];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 10)];
    return vi;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 54;
    }else{
        return 0.1;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return self.sectionFooterView;
    }else{
        return [[UIView alloc] init];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EditCharteredOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EditCharteredOrderCell"];
    if (self.isSingle) {
        cell.title.text = self.singleDataList[indexPath.section][indexPath.row];
    }else{
        cell.title.text = self.doubleDataList[indexPath.section][indexPath.row];
    }
    
    if (indexPath.section == 2) {
        cell.contentLabel.hidden = YES;
        cell.contentTextField.hidden = NO;
        cell.contentTextField.keyboardType = UIKeyboardTypeNumberPad;
    }else{
        cell.contentLabel.hidden = NO;
        cell.contentTextField.hidden = YES;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark ---- 单程 ----
- (IBAction)singleAction:(id)sender
{
    self.isSingle = YES;
    [self.singleButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.doubleButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    [self.allDayButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    self.charteredBusType = Enum_CharteredBusType_Items_single;
    CGPoint center = self.slideView.center;
    center.x = self.singleButton.center.x;
    self.slideView.center = center;
    [self.tableView reloadData];
}

#pragma mark ---- 往返 ----
- (IBAction)doubleAction:(id)sender
{
    self.isSingle = NO;
    [self.doubleButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.allDayButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    [self.singleButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    self.charteredBusType = Enum_CharteredBusType_Items_double;
    CGPoint center = self.slideView.center;
    center.x = self.doubleButton.center.x;
    self.slideView.center = center;
    [self.tableView reloadData];
}

#pragma mark ---- 包天 ----
- (IBAction)allDayAction:(id)sender
{
    self.isSingle = NO;
    [self.allDayButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.singleButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    [self.doubleButton setTitleColor:UI_RGBA_HEX(0x333333) forState:UIControlStateNormal];
    self.charteredBusType = Enum_CharteredBusType_Items_allDay;
    CGPoint center = self.slideView.center;
    center.x = self.allDayButton.center.x;
    self.slideView.center = center;
    [self.tableView reloadData];
}

#pragma mark ---- 下一步 ----
- (IBAction)nextButtonAction:(id)sender
{
    EditCharteredOrderNextViewController *vc = [[UIStoryboard storyboardWithName:@"MyCharteredBus" bundle:nil] instantiateViewControllerWithIdentifier:@"EditCharteredOrderNextViewController"];
    vc.hidesBottomBarWhenPushed = YES;
    vc.charteredBusType = self.charteredBusType;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
